--[[
    Author          ZhengFeng
    Time            2020.12.08
    Description     宠物申请界面-申请批准信息
]]--

require "Common/define"
require "Logic/PetManager"
local Page_PetApplyConfirm = UIBase.New(PanelResNames.Page_PetApplyConfirm)
local this = Page_PetApplyConfirm


function this.Init(in_type)
    this.PageType = in_type
    UIBase.Init(this)
end

function this:OnCreate()
    self.Btn_BGClose = self:GetChild("Btn_BGClose")
    self:RegisterOnClick(self.Btn_BGClose,self.onClickClose)
    self.Txt_PanelTitle = self:GetChild("Txt_PanelTitle")
    
    self.Txt_Check = self:GetChild("Txt_Check")
    self.Btn_Confirm = self:GetChild("Btn_Confirm")
    self:RegisterOnClick(self.Btn_Confirm,self.onClickConfirm)
    self.Btn_Refuse = self:GetChild("Btn_Refuse")
    self:RegisterOnClick(self.Btn_Refuse,self.onClickRefuse)

end

function this:OnEnable()
  this:showPanel()
end

function this:OnDisable()
    
end
function this:OnDestroy()
    
end

function this:onClickClose()
    closeUI(PanelResNames.Page_PetApplyConfirm)
end


function this:showPanel()
    if this.PageType == BrokerUtils.PETSHOP_PetType then
        self.Btn_Confirm.title = getLanguage("PETSHOP_ConfirmTitle")
        self.Btn_Refuse.title = getLanguage("PETSHOP_CancelTitle")
        this.detailPetInfo = clone(BrokerManager.GetPetInfoByPetId(BrokerManager.DetailSelectedPetId,BrokerManager.BrokerPetType))
        self.Txt_PanelTitle.text = getLanguage("PETSHOP_DetailBuyTitle")
        self.Txt_Check.text = string.format(getLanguage("PETSHOP_PetBuyWarning"),this.detailPetInfo.sellPrice,this.detailPetInfo.petName)
    else
        self.Btn_Confirm.title = getLanguage("PET_ApplyConfirm")
        self.Btn_Refuse.title = getLanguage("PET_ApplyCancel")
        self.Txt_PanelTitle.text = getLanguage("PetApply_Confirm")  --"申请核准"
        local _applyInfo = logicMgr.PetManager.applies[PetManager.SelectedOthersApplyIndex]
        local _check = ""
        if _applyInfo ~= nil then
            --"是否批准玩家 %s 的申请"
            _check = string.format(getLanguage("PetApply_Check"),_applyInfo.fromPlayerName)
        end
        self.Txt_Check.text = _check
    end
end

function this:onClickConfirm()
    if this.PageType == BrokerUtils.PETSHOP_PetType then
        if BrokerManager.CheckIsMyPlayer(this.detailPetInfo.playerId) then
            UISysTips.AddMsg(getLanguage("PETSHOP_BuyPetIsMineError"))
        else
            BrokerHandler.ReqBrokerGoodsBuy(this.detailPetInfo.goodsId)
            PetManager.Track_buyPet(this.detailPetInfo.playerId, this.detailPetInfo.genes)
        end
    else
        local _applyInfo = logicMgr.PetManager.applies[PetManager.SelectedOthersApplyIndex]
        PetHandler.ReqAgreeMating(_applyInfo.templatePetInfo.petId,_applyInfo.mutatePetInfo.petId)
    end
    self:onClickClose()
end
function this:onClickRefuse()
    if this.PageType == BrokerUtils.PETSHOP_PetType then
        self:onClickClose()
        return
    end
    local _applyInfo = logicMgr.PetManager.applies[PetManager.SelectedOthersApplyIndex]
    PetHandler.ReqRefuseMating(_applyInfo.templatePetInfo.petId,_applyInfo.mutatePetInfo.petId)
    self:onClickClose()
end

return this